package com.zx.tv.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;

import com.zx.base.http.URLHelper;
import com.zx.base.lazylist.ImageLoader;
import com.zx.tv.R;
import com.zx.tv.entity.NewListPic;

public class NewListImgAdapter extends BaseAdapter {

	private ArrayList<NewListPic> list = new ArrayList<NewListPic>();
	private ImageLoader imageLoader;
	private LayoutInflater inflater;
	private ViewHolder holder = null;
	
	public NewListImgAdapter(Context context, ArrayList<NewListPic> img,
			ImageLoader imageLoader) {
		list = img;
		this.imageLoader = imageLoader;
		this.inflater=LayoutInflater.from(context);
	}

	public int getCount() {
		return Integer.MAX_VALUE;
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		NewListPic info = new NewListPic() ;
		if (convertView == null) {
			convertView=inflater.inflate(R.layout.news_list_pic_item, null);
			holder=new ViewHolder();
			holder.news_pic =(ImageView)convertView.findViewById(R.id.news_item_icon);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder)convertView.getTag();
		}
		
		if(position < 0){
			position = position + list.size();
		}
		
		if(0 == list.size()){
			
		}else{
			info=list.get(position% list.size());
		}
		
		imageLoader.DisplayImage(URLHelper.mPrefixImg+info.getImg_url(), holder.news_pic, R.drawable.loading);
		
		
		return convertView;
	}
	
	static class ViewHolder{
		public ImageView news_pic;
		
	}

}